#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <unistd.h>

#define MAXLINE 4096

int main() {
	int n;
	int fd[2];
	pid_t pid;
	char line[MAXLINE];

	if (pipe(fd) < 0) {
		printf("pipe error: %s\n", strerror(errno));
		return -1;
	}

	if ((pid=fork()) < 0) {
		printf("fork error: %s\n", strerror(errno));
		return -1;
	}
	else if (pid > 0) {
		close(fd[0]);
		write(fd[1], "hello world\n", 12);
	}
	else {
		close(fd[1]);
		sleep(2);
		n = read(fd[0], line, MAXLINE);
		write(STDIN_FILENO, line, n);
	}

	return 0;
}